# makefile
#  build with git revision number
#  example:  gb build -ldflags "-X main.build=`git rev-parse HEAD`" cmd/xxx

# varible
CMD = rc
CURRENT_REVISION = `git rev-parse HEAD`
LD_FLAGS := "-X main.build=$(CURRENT_REVISION)"

BIN_CMD = ../../bin/${CMD}
RELEASE_DIR = ./release

# target
all: cmd

# release
release:
	@echo "[begin] release ==================="
	GOOS=darwin GOARCH=amd64 go build -ldflags ${LD_FLAGS} -o ${CMD}-darwin-amd64
	GOOS=linux GOARCH=amd64 go build -ldflags ${LD_FLAGS} -o ${CMD}-linux-amd64
	GOOS=windows GOARCH=amd64 go build -ldflags ${LD_FLAGS} -o ${CMD}-windows-amd64.exe
	tar czvf release.tar.gz ${CMD}-darwin-amd64 ${CMD}-windows-amd64.exe ${CMD}-linux-amd64
	@echo "[end]   release ==================="

cmd: clean
	@echo "[begin] build rc ==================="
	go install -ldflags ${LD_FLAGS}
	@echo "[end  ] build rc ==================="

.PHONY: clean
clean:
	rm -f ${BIN_CMD}
	rm -f ${CMD}-darwin-amd64
	rm -f ${CMD}-windows-amd64.exe
	rm -f ${CMD}-linux-amd64

help:
	@echo "make [option]: "
	@echo "\t all     : compile for all binaries"
	@echo "\t release : generate tar file with compiled binary(windows, linux, osx)"
	@echo "\t cmd     : compile for main command"
	@echo "\t clean   : clean files which are generated by compile"
	@echo "\t help    : print this help info"
	@echo "\n"
	@echo "make == make all"
